<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function useMutationObserver(callback) {
        let iterations = 0;
        const observer = new MutationObserver(callback);
        const node = document.createTextNode('');
        // characterData 设为 true 以监视指定目标节点或子节点树中节点所包含的字符数据的变化。
        observer.observe(node, {characterData: true});

        return function () {
            node.data = iterations = ++iterations % 2;
        };
    }

    console.log('start')

    setTimeout(() => console.log('setTimeout'))

    let microtask = useMutationObserver(() => {
        for (let i = 0; i < 1000000000; i++) {
            if (i === 999999999) {
                console.log('Hello MutationObserver!')
            }
        }
    })
    microtask()

    console.log('end')

</script>
</body>
</html>
